package com.edu.exam.entity.assessment.technical;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 查重历史实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：check_history
 *
 * 根据B-02-06试题查重子模块设计文档实现
 * 管理试题查重历史记录，支持历史查询、统计分析和趋势监控。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "check_history")
@Comment("查重历史表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CheckHistory {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 查重历史唯一标识符
     */
    @NotBlank(message = "查重历史ID不能为空")
    @Size(max = 50, message = "查重历史ID长度不能超过50个字符")
    @Column(name = "history_id", nullable = false, length = 50, unique = true)
    private String historyId;

    /**
     * 查重记录ID（关联到question_check_records表）
     */
    @Size(max = 50, message = "查重记录ID长度不能超过50个字符")
    @Column(name = "record_id", length = 50)
    private String recordId;

    /**
     * 试题ID
     */
    @NotNull(message = "试题ID不能为空")
    @Column(name = "question_id", nullable = false)
    private Long questionId;

    /**
     * 试题版本号
     */
    @Size(max = 20, message = "试题版本号长度不能超过20个字符")
    @Column(name = "question_version", length = 20)
    private String questionVersion;

    /**
     * 查重类型（REAL_TIME-实时查重，BATCH-批量查重，MANUAL-人工查重，SCHEDULED-定时查重）
     */
    @NotBlank(message = "查重类型不能为空")
    @Size(max = 20, message = "查重类型长度不能超过20个字符")
    @Column(name = "check_type", nullable = false, length = 20)
    private String checkType;

    /**
     * 操作类型（CREATE-创建查重，UPDATE-更新查重，DELETE-删除查重，REVIEW-审核查重，EXPORT-导出结果）
     */
    @NotBlank(message = "操作类型不能为空")
    @Size(max = 20, message = "操作类型长度不能超过20个字符")
    @Column(name = "operation_type", nullable = false, length = 20)
    private String operationType;

    /**
     * 查重范围（ALL-全部试题，LIBRARY-指定题库，SUBJECT-指定学科，CUSTOM-自定义范围）
     */
    @Size(max = 20, message = "查重范围长度不能超过20个字符")
    @Column(name = "check_scope", length = 20)
    private String checkScope;

    /**
     * 查重时间
     */
    @NotNull(message = "查重时间不能为空")
    @Column(name = "check_time", nullable = false)
    private LocalDateTime checkTime;

    /**
     * 查重耗时（毫秒）
     */
    @Column(name = "check_duration")
    private Long checkDuration;

    /**
     * 操作前状态
     */
    @Size(max = 1000, message = "操作前状态长度不能超过1000个字符")
    @Column(name = "previous_state", columnDefinition = "TEXT")
    private String previousState;

    /**
     * 操作后状态
     */
    @Size(max = 1000, message = "操作后状态长度不能超过1000个字符")
    @Column(name = "new_state", columnDefinition = "TEXT")
    private String newState;

    /**
     * 相似度得分（如果有）
     */
    @Column(name = "similarity_score", precision = 5, scale = 4)
    private BigDecimal similarityScore;

    /**
     * 相似度等级
     */
    @Size(max = 20, message = "相似度等级长度不能超过20个字符")
    @Column(name = "similarity_level", length = 20)
    private String similarityLevel;

    /**
     * 发现相似试题数量
     */
    @Column(name = "similar_questions_count")
    private Integer similarQuestionsCount;

    /**
     * 高相似度试题数量
     */
    @Column(name = "high_similarity_count")
    private Integer highSimilarityCount;

    /**
     * 中相似度试题数量
     */
    @Column(name = "medium_similarity_count")
    private Integer mediumSimilarityCount;

    /**
     * 低相似度试题数量
     */
    @Column(name = "low_similarity_count")
    private Integer lowSimilarityCount;

    /**
     * 算法配置（JSON格式，使用的算法配置）
     */
    @Column(name = "algorithm_config", columnDefinition = "TEXT")
    private String algorithmConfig;

    /**
     * 算法版本
     */
    @Size(max = 20, message = "算法版本长度不能超过20个字符")
    @Column(name = "algorithm_version", length = 20)
    private String algorithmVersion;

    /**
     * 操作人员ID
     */
    @NotBlank(message = "操作人员ID不能为空")
    @Size(max = 50, message = "操作人员ID长度不能超过50个字符")
    @Column(name = "operator_id", nullable = false, length = 50)
    private String operatorId;

    /**
     * 操作人员姓名
     */
    @Size(max = 100, message = "操作人员姓名长度不能超过100个字符")
    @Column(name = "operator_name", length = 100)
    private String operatorName;

    /**
     * 操作人员角色
     */
    @Size(max = 50, message = "操作人员角色长度不能超过50个字符")
    @Column(name = "operator_role", length = 50)
    private String operatorRole;

    /**
     * 操作IP地址
     */
    @Size(max = 45, message = "操作IP地址长度不能超过45个字符")
    @Column(name = "operator_ip", length = 45)
    private String operatorIp;

    /**
     * 操作设备信息
     */
    @Size(max = 200, message = "操作设备信息长度不能超过200个字符")
    @Column(name = "operator_device", length = 200)
    private String operatorDevice;

    /**
     * 操作结果（SUCCESS-成功，FAILED-失败，PARTIAL-部分成功）
     */
    @Size(max = 20, message = "操作结果长度不能超过20个字符")
    @Column(name = "operation_result", length = 20)
    private String operationResult;

    /**
     * 错误信息
     */
    @Size(max = 1000, message = "错误信息长度不能超过1000个字符")
    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;

    /**
     * 操作详情（JSON格式，详细操作信息）
     */
    @Column(name = "operation_details", columnDefinition = "TEXT")
    private String operationDetails;

    /**
     * 变更内容（JSON格式，记录具体的变更内容）
     */
    @Column(name = "changes", columnDefinition = "TEXT")
    private String changes;

    /**
     * 变更字段列表（JSON数组格式）
     */
    @Column(name = "changed_fields", columnDefinition = "TEXT")
    private String changedFields;

    /**
     * 相关记录ID列表（JSON数组格式，关联的其他记录）
     */
    @Column(name = "related_records", columnDefinition = "TEXT")
    private String relatedRecords;

    /**
     * 附件信息（JSON格式，相关附件信息）
     */
    @Column(name = "attachments", columnDefinition = "TEXT")
    private String attachments;

    /**
     * 批次ID（如果是批量操作）
     */
    @Size(max = 50, message = "批次ID长度不能超过50个字符")
    @Column(name = "batch_id", length = 50)
    private String batchId;

    /**
     * 会话ID
     */
    @Size(max = 50, message = "会话ID长度不能超过50个字符")
    @Column(name = "session_id", length = 50)
    private String sessionId;

    /**
     * 请求ID（用于跟踪请求链路）
     */
    @Size(max = 50, message = "请求ID长度不能超过50个字符")
    @Column(name = "request_id", length = 50)
    private String requestId;

    /**
     * 触发方式（MANUAL-手动触发，AUTO-自动触发，SCHEDULED-定时触发，API-API触发）
     */
    @Size(max = 20, message = "触发方式长度不能超过20个字符")
    @Column(name = "trigger_method", length = 20)
    private String triggerMethod;

    /**
     * 系统环境（JSON格式，操作时的系统环境信息）
     */
    @Column(name = "system_environment", columnDefinition = "TEXT")
    private String systemEnvironment;

    /**
     * 业务上下文（JSON格式，业务上下文信息）
     */
    @Column(name = "business_context", columnDefinition = "TEXT")
    private String businessContext;

    /**
     * 扩展属性（JSON格式，其他扩展信息）
     */
    @Column(name = "extended_attributes", columnDefinition = "TEXT")
    private String extendedAttributes;

    /**
     * 创建者ID
     */
    @NotBlank(message = "创建者ID不能为空")
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

 
}
